<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link href="../../libs/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="../../libs/app.css"/>
    <link href="../../css/main.css" rel="stylesheet"/>
    <link href="../../css/credit.css" rel="stylesheet"/>
</head>

<body>
<div class="head">
    <img class="mui-action-back" src="../../images/all-left.png" alt="">
    <p>信用贷</p>
</div>
<div class="credit-context">
    <div class="credit-select" id="credit-select">
        <div class="active">
            <p class="active-p">人寿保单贷</p>
        </div>
        <div>
            <p class="no-active-p">房贷月供贷</p>
        </div>
        <div>
            <p class="no-active-p">优良职业贷</p>
        </div>
        <div>
            <p class="no-active-p">公司经营贷</p>
        </div>
    </div>

    <p class="title-p">机构合作贷款100个</p>
    <div class="title" id="title">

        <div class="life" id="rsbd" style="display: block"></div>

        <div class="house" id="fdyg" style="display: none"></div>

        <div class="work" id="ylzy" style="display: none"></div>

        <div class="company" id="gsjx" style="display: none">
            <!--<div class="context"  onclick="href('personal.html','personal')">
             <div class="left">
                 <div class="head-photo">
                 </div>
             </div>
             <div class="right">
                 <p class="right-p">工商银行-公司经营贷款</p>
                 <p class="how-people"><span>137</span>人申请/<span>3</span>天放款</p>
                 <p>可贷<span>50.0</span>-<span>100.0</span>万&nbsp&nbsp分期还款</p>
                 <p><span class="hui">0.31%</span>/月</p>
             </div>
         </div>-->
        </div>
    </div>
</div>
<script src="../../libs/mui.min.js"></script>
<script src="../../js/jquery-3.1.1.min.js"></script>
<script src="../../js/url.js"></script>
<script type="text/javascript">
    $(function () {
        var tab = localStorage.getItem('ylzy_tab');
        tab && $('#credit-select>div').eq(tab).trigger('tap');
        localStorage.removeItem('ylzy_tab');
    });

    localStorage.dk_type = 'xyd';
    //tab切换
    $('#credit-select>div').on('tap', function () {
        var $this = $(this);
        $this.addClass('active').siblings().removeClass('active');
        $this.children().removeClass('no-active-p').addClass('active-p');
        $this.siblings().children().removeClass('active-p').addClass('no-active-p');
        $('.title > div').eq($this.index()).show(0).siblings().hide(0);
    });

    var Credit = function (loanCode, className) {
        this.page = 1;
        this.loanCode = loanCode;
        this.className = className;
    };
    Credit.prototype = {
        getAjax: function () {
            var _this = this;
            $.ajax({
                url: ur + 'rest/creditLoanController/list',
                type: 'get', dataType: 'json', headers: {"X-Token": localStorage.token},
                data: {
                    loanCode: _this.loanCode,
                    page: _this.page
                }
            })
                .done(function (data) {
                    if (data.meta.code == 'S002') {
                        var s = data.data.list.length;
                        var totalPage = Math.ceil(data.data.total / 10);
                        var isMore = $(_this.className).find('.more');
                        var more = '<p class="more">点击加载更多</p>';
                        for (var i = 0; i < s; i++) {
                            var list = $('<div class="context"  id=' + data.data.list[i].id + ' type=' + _this.loanCode + '>' +
                                '<div class="left">' +
                                '<div class="head-photo" style="background-image: url(' + ur + data.data.list[i].image + ')">' +
                                '</div>' +
                                '</div>' +
                                '<div class="right">' +
                                '<p class="right-p">' + data.data.list[i].title + '</p>' +
                                '<p class="how-people"><span>' + data.data.list[i].sum + '</span>人申请/<span>' + data.data.list[i].loanTime + '</span>天放款</p>' +
                                '<p>可贷<span>' + data.data.list[i].loanMinMoney + '</span>-<span>' + data.data.list[i].loanMaxMoney + '</span>万元 <span class="right-type"></span></p>' +
                                '<p><span class="hui">' + data.data.list[i].interest + '%</span>/月</p>' +
                                '</div>' +
                                '</div>');
                            if (isMore.length == 0) {
                                $(_this.className).append(list);
                            } else {
                                isMore.before(list);
                            }
                            if (data.data.list[i].instalment == 'Y') {
                                $(_this.className + '>div').eq(i).find('.right-type').text('分期付款');
                            } else {
                                $(_this.className + '>div').eq(i).find('.right-type').text('不可分期');
                            }
                        }
                        if (totalPage != 1) {
                            if (isMore.length == 0) {
                                $(_this.className).append(more);
                            } else if (_this.page == totalPage) {
                                isMore.text('已无更多');
                            }
                            $(_this.className).on('tap', '.more', function () {
                                if (_this.page < totalPage) {
                                    _this.page++;
                                    _this.getAjax();
                                }
                            })
                        }
                    }
                })
        },
    }
    var rsbd = new Credit('rsbd', '#rsbd') //人寿保单贷
    rsbd.getAjax()
    var fgyg = new Credit('fdyg', '#fdyg') //房供月供贷
    fgyg.getAjax()
    var ylzy = new Credit('ylzy', '#ylzy') //优良职业贷
    ylzy.getAjax()
    var gsjx = new Credit('gsjx', '#gsjx') //公司经营贷
    gsjx.getAjax()
    //页面跳转
    $('#title').on('tap', '.context', function () {
        var $this = $(this);
        localStorage.yyd_type = $this.attr('type');
        localStorage.yyd_id = $this.attr('id');
        localStorage.loanCode = $this.parent().attr('id');
//        href('personal.html', 'personal.html', {loanId: $this.attr('id'), type: $this.attr('type')});
        href('personal.html', 'personal.html');
        localStorage.setItem('credit-personal', JSON.stringify({
            loanId: $this.attr('id'),
            type: $this.attr('type'),
            bank: $this.find('.right-p').html()
        }));
    });
</script>
</body>

</html>